<?php

//+++++++++++++++++++++++++++++++++++++++++
//カスタムヘッダー
add_custom_image_header('','admin_header_style');
function admin_header_style() {}

//標準のヘッダー画像を指定
define('HEADER_IMAGE','%s/images/header.jpg');

//ヘッダー画像の横幅と高さを指定
define('HEADER_IMAGE_WIDTH','256');
define('HEADER_IMAGE_HEIGHT','88');

//ヘッダーの文字を隠す
define('NO_HEADER_TEXT',true);

//背景画像を指定
add_custom_background();

//記事のpタグを削除
remove_filter('the_content', 'wpautop');

//+++++++++++++++++++++++++++++++++++++++++
//カスタムメニュー

register_nav_menus(array(
	'navbar' => 'ナビゲーションバー',
	'sidebar' => 'サイドバー'
	));

//+++++++++++++++++++++++++++++++++++++++++
//エディタ・スタイルシート

add_editor_style();

//+++++++++++++++++++++++++++++++++++++++++
//ウィジェット登録

register_sidebar(array(
	'description'   => '',
	'before_widget' => '',
	'after_widget'  => '',
	'before_title'  => '',
	'after_title'   => ''
	)
);

register_sidebar(array(
	'description'   => '',
	'before_widget' => '',
	'after_widget'  => '',
	'before_title'  => '',
	'after_title'   => ''
	)
);

//ウィジェットタイトル非表示
function my_widget_title( $title ) {
  return '';
}
add_filter( 'widget_title', 'my_widget_title' );

//+++++++++++++++++++++++++++++++++++++++++
// アイキャチ画像

add_theme_support('post-thumbnails');
set_post_thumbnail_size(120, 90, true);
//set_post_thumbnail_size(120, 90);

//+++++++++++++++++++++++++++++++++++++++++
// アイキャチ画像のURLを取得
function get_featured_image_url() { 
    $image_id = get_post_thumbnail_id();
    $image_url = wp_get_attachment_image_src($image_id, 'thumbnail', true); 
    echo $image_url[0]; 
}

//+++++++++++++++++++++++++++++++++++++++++
// 管理バーを消す
add_filter( 'show_admin_bar', '__return_false' );

//+++++++++++++++++++++++++++++++++++++++++
// ログイン画面ロゴ
function custom_login_logo() {
    echo '<style type="text/css">h1 a { background: url('.get_bloginfo('template_directory').'/images/tool/master_control_image.png) 50% 50% no-repeat !important; }</style>';
}
add_action('login_head', 'custom_login_logo');

//+++++++++++++++++++++++++++++++++++++++++
// 管理画面左上のロゴ
add_action('admin_head', 'my_custom_logo');
function my_custom_logo() {
echo '<style type="text/css">#header-logo { background-image:url('.get_bloginfo('template_directory').'/images/tool/master_control_logo.png) !important; }</style>';
}

//+++++++++++++++++++++++++++++++++++++++++
//  管理画面フッターのテキスト
function custom_admin_footer() {
    echo '© CYBIRD Co., Ltd All Rights Reserved.';
}
add_filter('admin_footer_text', 'custom_admin_footer');

//+++++++++++++++++++++++++++++++++++++++++
// HTML エディタのフォントを変更
function change_editor_font(){
echo "<style type='text/css'>
#editorcontainer textarea#content {
  font-family: \"ヒラギノ角ゴ Pro W3\",
    \"Hiragino Kaku Gothic Pro\",
    Osaka,
    \"ＭＳ Ｐゴシック\",
    sans-serif;
  font-size:14px;
  color:#333;
}
</style>";
}
add_action("admin_print_styles", "change_editor_font");

//+++++++++++++++++++++++++++++++++++++++++
// アドミンバーを消す
add_filter('show_admin_bar','__return_false');

//+++++++++++++++++++++++++++++++++++++++++
// 管理者以外にアップデートのお知らせ非表示
if (!current_user_can('edit_users')) {
  function wphidenag() {
    remove_action( 'admin_notices', 'update_nag');
  }
  add_action('admin_menu','wphidenag');
}

//+++++++++++++++++++++++++++++++++++++++++
// 管理者以外にダッシュボードの内容非表示
if (!current_user_can('edit_users')) {
remove_all_actions('wp_dashboard_setup');
function example_remove_dashboard_widgets() {
    global $wp_meta_boxes;

    //Main column
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);

    //Side Column
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
  }
add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );
}

//+++++++++++++++++++++++++++++++++++++++++
// 管理者以外は［表示オプション］［ヘルプ］のタブを非表示にする
if (!current_user_can('edit_users')) {

function my_admin_print_styles(){
  echo '
  <style type="text/css">
  #screen-options-link-wrap,
  #contextual-help-link-wrap{display:none;}
  </style>';
  }
add_action('admin_print_styles', 'my_admin_print_styles', 21);
}

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト Event情報

register_post_type(
	'event', 
	array(
		'label' => 'イベント情報',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/event.png',
		'supports' => array(
			'title', 
			'editor'
		)
	)
);


//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト photogallery

register_post_type(
	'photogallery', 
	array(
		'label' => 'フォトギャラリー',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/media.png',
		'supports' => array(
			'title', 
			'editor',
			'custom-fields',
			'thumbnail'
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト DISCOGRAPHY
register_post_type(
	'discography', 
	array(
		'label' => 'ディスコグラフィー',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/discography.png',
		'supports' => array(
			'title', 
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト MEDIA
register_post_type(
	'media', 
	array(
		'label' => 'メディア/出演情報',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/media.png',
		'supports' => array(
			'title', 
			'editor',
			'custom-fields'
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト BLOG
register_post_type(
	'blog', 
	array(
		'label' => 'ブログ',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/blog.png',
		'supports' => array(
			'title', 
			'editor', 
			'custom-fields'
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト MULTI-BLOG
register_post_type(
	'multiblog', 
	array(
		'label' => 'マルチブログ',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/blog.png',
		'supports' => array(
			'title', 
			'editor', 
			'custom-fields'
		)
	)
);


//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト ITUNES
register_post_type(
	'itunes', 
	array(
		'label' => 'iTunes',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/itune.png',
		'supports' => array(
			'title',  
			'editor'
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト GOODS
register_post_type(
	'goods', 
	array(
		'label' => 'グッズ',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/goods.png',
		'supports' => array(
			'title',
			'thumbnail'
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト Twitter
register_post_type(
	'twitter', 
	array(
		'label' => 'Twitter',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/twitter.png',
		'supports' => array(
			'title'
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト YouTube
register_post_type(
	'youtube', 
	array(
		'label' => 'YouTube',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/youtube.png',
		'supports' => array(
			'title'
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト Profile
register_post_type(
	'profile', 
	array(
		'label' => 'プロフィール',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/profile.png',
		'supports' => array(
			'editor'
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト MasterControl Setting
register_post_type(
	'mastercontrol', 
	array(
		'label' => 'MasterControl',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/master_control_logo.png',
		'supports' => array(
			'title'
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト メニュー構成
register_post_type(
	'menucontrol', 
	array(
		'label' => 'メニュー構成',
		'hierarchical' => false,
		'public' => true,
		'query_var' => false,
		'menu_icon' => get_bloginfo('template_url').'/images/tool/master_control_logo.png',
		'supports' => array(
			'title'
		)
	)
);

//+++++++++++++++++++++++++++++++++++++++++
// カスタムポスト おすすめコーデ
register_post_type(
        'osusume',
        array(
                'label' => 'おすすめコーデ',
                'hierarchical' => false,
                'public' => true,
                'query_var' => false,
                'menu_icon' => get_bloginfo('template_url').'/images/tool/youtube.png',
                'supports' => array(
			'title', 
			'editor',
			'custom-fields'
                )
        )
);


//+++++++++++++++++++++++++++++++++++++++++
//パンくずリスト用(未使用)
function get_breadcrumbs(){
	global $wp_query;

	if ( !is_home() ){

		// Add the Home link
		echo '<a href="'. get_settings('home') .'">TOP</a>';

		if ( is_category() )
		{
			$catTitle = single_cat_title( "", false );
			$cat = get_cat_ID( $catTitle );
			echo '&gt;<span class="now">'. get_category_parents( $cat, TRUE, "" ) .'</span>';
		}
		elseif ( is_archive() && !is_category() )
		{
			echo '&gt;&nbsp;<span class="now">Archives</span>';
		}
		elseif ( is_search() ) {

			echo '&gt;&nbsp;<span class="now">Search Results</span>';
		}
		elseif ( is_404() )
		{
			echo '&gt;&nbsp;<span class="now">404 Not Found</span>';
		}
		elseif ( is_single() )
		{
			$category = get_the_category();
			$category_id = get_cat_ID( $category[0]->cat_name );

			echo '&gt;<span class="now">'. get_category_parents( $category_id, TRUE, "&gt;" );
			echo '&nbsp;&nbsp;' . the_title('','', FALSE) ."</span>";
		}
		elseif ( is_page() )
		{
			$post = $wp_query->get_queried_object();

			if ( $post->post_parent == 0 ){

				echo '&nbsp;&gt;&nbsp;<span class="now">'.the_title('','', FALSE).'</span>';

			} else {
				$title = the_title('','', FALSE);
				$ancestors = array_reverse( get_post_ancestors( $post->ID ) );
				array_push($ancestors, $post->ID);

				foreach ( $ancestors as $ancestor ){
					if( $ancestor != end($ancestors) ){
						echo '&nbsp;&gt;&nbsp; <a href="'. get_permalink($ancestor) .'">'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</a>';
					} else {
						echo '&nbsp;&gt;&nbsp; <span class="now">'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</span>';
					}
				}
			}
		}
	}
}

//+++++++++++++++++++++++++++++++++++++++++
// ギャラリー用facebookいいねボタン追加

/* デフォルトのショートコードを削除 */
remove_shortcode('gallery', 'gallery_shortcode');

/* 新しい関数を定義 */
add_shortcode('gallery', 'my_gallery_shortcode');

function my_gallery_shortcode($attr) {
  global $post, $wp_locale;

  static $instpe = 0;
  $instpe++;

  // Allow plugins/themes to override the default gallery template.
  $output = apply_filters('post_gallery', '', $attr);
  if ( $output != '' )
    return $output;

  // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
  if ( isset( $attr['orderby'] ) ) {
    $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
    if ( !$attr['orderby'] )
      unset( $attr['orderby'] );
    }

  extract(shortcode_atts(array(
    'order'      => 'ASC',
    'orderby'    => 'menu_order ID',
    'id'         => $post->ID,
    'itemtag'    => 'dl',
    'icontag'    => 'dt',
    'captiontag' => 'dd',
    'columns'    => 3,
    'size'       => 'thumbnail',
    'include'    => '',
    'exclude'    => ''
  ), $attr));

  $id = intval($id);
  if ( 'RAND' == $order )
    $orderby = 'none';

  if ( !empty($include) ) {
    $include = preg_replace( '/[^0-9,]+/', '', $include );
    $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );

    $attachments = array();
    foreach ( $_attachments as $key => $val ) {
      $attachments[$val->ID] = $_attachments[$key];
    }
  } elseif ( !empty($exclude) ) {
    $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
    $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  } else {
    $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  }

  if ( empty($attachments) )
    return '';

  if ( is_feed() ) {
    $output = "¥n";
    foreach ( $attachments as $att_id => $attachment )
      $output .= wp_get_attachment_link($att_id, $size, true) . "¥n";
    return $output;
  }

  $itemtag = tag_escape($itemtag);
  $captiontag = tag_escape($captiontag);
  $columns = intval($columns);
  $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
  $float = is_rtl() ? 'right' : 'left';

  $selector = "gallery-{$instpe}";

  $output = apply_filters('gallery_style', "
    <style type='text/css'>
      #{$selector} {
        margin: auto;
      }
      #{$selector} .gallery-item {
        float: {$float};
        margin-top: 10px;
        text-align: center;
        width: {$itemwidth}%;			}
      #{$selector} img {
        border: 2px solid #cfcfcf;
      }
      #{$selector} .gallery-caption {
        margin-left: 0;
      }
    </style>
    <!-- see gallery_shortcode() in wp-includes/media.php -->
    <div id='$selector' class='gallery galleryid-{$id}'>");

  $i = 0;
  foreach ( $attachments as $id => $attachment ) {
    $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
    $output .= "<{$itemtag} class='gallery-item'>";
    $output .= "
      <{$icontag} class='gallery-icon'>
        $link
      </{$icontag}>";
    if ( $captiontag && trim($attachment->post_excerpt) ) {
      $output .= "
        <{$captiontag} class='gallery-caption'>
        " . wptexturize($attachment->post_excerpt) . "
        </{$captiontag}>";
    }
	$url_thumbnail = wp_get_attachment_image_src($id, $size='thumbnail');
	
	$url = urlencode(get_bloginfo('home') . '/?attachment_id=' . $id);
	$url .= urlencode('&app_data=' . get_bloginfo('home') . '/?attachment_id=' . $id);

	$output .= '<p><div class="btn_like"><iframe src="http://www.facebook.com/plugins/like.php?href=';
	$output .= $url;
	$output .= '&amp;id=fb&amp;send=false&amp;layout=button_count&amp;show_faces=false&amp;width=120&amp;action=like&amp;colorscheme=light$amp;locale=ja_JA&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:120px; height:21px;" allowTransparency="true"></iframe></div></p>';

    $output .= "</{$itemtag}>";

    if ( $columns > 0 && ++$i % $columns == 0 )
      $output .= '<br style="clear: both" />';
  }
  $output .= "</div>";
  return $output;
}

function remove_gallery_css() {
  return "<div id='gallery_box'>";
}
add_filter('gallery_style', 'remove_gallery_css');

function fix_gallery_output( $output ){
  $output = preg_replace("%<br style=.*clear: both.* />%", "", $output);
  $output = preg_replace("%<dl class='gallery-item'>%", "<div class='photobox'>", $output);
  $output = preg_replace("%<dt class='gallery-icon'>%", "", $output);
  $output = preg_replace("%</dl>%", "</div>", $output);
  $output = preg_replace("%</dt>%", "", $output);
  return $output;
}
add_filter('the_content', 'fix_gallery_output',11, 1);
//+++++++++++++++++++++++++++++++++++++++++

?>
